#include<bits/stdc++.h>
using namespace std;

int T, n, a[200005], ans = 0xcfffffff, cnt, color[200005];

int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin >> T;
    while(T--){
        cin >> n;
        ans = 0xcfffffff;
        for(int i = 1; i <= n; i++)
            cin >> a[i];
        for(int state = 0; state < (1<<(n+1)); state++){
            cnt = 0;
            for(int i = 0; i < n; i++){
                color[i+1] = state & (1<<i);
            }
            for(int i = 1; i <= n; i++){
                for(int j = i - 1; j >= 1; j--){
                    if(color[j] == color[i] and a[i] == a[j]){
                        cnt += a[i];
                        break;
                    }
                }
            }
            ans = max(ans, cnt);
        }
        cout << ans << endl;
    }
    return 0;
}
